using UnityEngine;

namespace JufGame.CptMod
{
	/// <summary>
	/// 记忆度：玩家对角色的有效记忆及发现其变化的可能性
	/// </summary>
	public class PlayerMemory
	{
		public float MemoryValue{ get; private set; } = 0;
		private const float RateMemorizing = 0.6f; //记忆率
		private const float RateForgetting = 0.05f; //遗忘率，该值还要乘上总注意程度负载
		private const float MAX_MEMORY = 1E+9f;
		private float k;
		// 记忆度的更新函数
		public void UpdateMemory(float currentAttention, float totalAtnLoad, float deltaTime)
		{
			// 判断选取记忆度的变化率
			k = MemoryValue < currentAttention ? RateMemorizing : (RateForgetting * totalAtnLoad);
			// 计算记忆度的变化量, 用EMA
			MemoryValue += k *(currentAttention - MemoryValue) * deltaTime;
			MemoryValue = Mathf.Clamp(MemoryValue, 0, MAX_MEMORY);
		}
	}
}
